package com.yihusitian.zsxq.sg.generator;

import com.yihusitian.zsxq.sg.config.BaseClassInfo;
import com.yihusitian.zsxq.sg.entity.FieldInfo;
import com.yihusitian.zsxq.sg.util.CommonInfoHolder;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @Description 模型对象生成器
 * @Author LeeHo
 * @Date 2020/8/27 10:30
 */
public class VOSourceGenerator extends DOSourceGenerator implements SourceGenerator {

    @Override
    public String getMainContent() {
        List<FieldInfo> fieldInfoList = CommonInfoHolder.getCurrentFieldInfoList();
        StringBuilder content = new StringBuilder();
        for (FieldInfo fieldInfo : fieldInfoList) {
            content.append(TAB_NEW_LINE);
            content.append(NOTE).append(fieldInfo.getComment()).append(TAB_NEW_LINE);
            content.append(String.format("@ApiModelProperty(value = \"%s\")", StringUtils.defaultString(fieldInfo.getComment()))).append(TAB_NEW_LINE);
            String importLine = this.getImportLine(fieldInfo);
            if (StringUtils.isNotEmpty(importLine)) {
                this.importSet.add(importLine);
            }
            content.append(String.format("private %s %s;", fieldInfo.getJavaType(), fieldInfo.getPropertyName())).append(TAB_NEW_LINE);
        }
        return content.toString();
    }

    @Override
    public BaseClassInfo getBaseClassInfo() {
        return generateConfigHolder.getVoInfo();
    }
}